<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>

<script type="text/javascript">
	
	function postRequest(variable)
	{
		var xmlHttp;
		if(window.XMLHttpRequest)
		{
			var xmlHttp = new XMLHttpRequest();
		}
		else if (window.ActiveXObject){
			var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlHttp.open('POST', variable,true);
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				alert(xmlHttp.responseText);
				updatepage(xmlHttp.responseText);
			}
		}
		
		xmlHttp.send(variable);
		
	}
	
	function updatepage(str)
	{
		if(str == "yes"){
			
			alert("Welcome User");
		}else{
			
			alert("Invalid User");
		}
	}
	
	
	function Alerta()
	{
		var nombre = window.document.f1.userName.value;
		var password = window.document.f1.userPass.value;
		var url = "login.jsp?userName="+nombre+"&userPass="+password;
		postRequest(url);
	}
	
</script>

</head>
<body>
	<form name="f1" onsubmit="return Alerta();">
	
	<div id="Usuario">
	
		User <input type="text" name="userName" id="User" value="" />
		Pass <input type="text" name="userPass" id="Pass" value="" />
	
		<input type="button" name="b1" value="Login" onclick="Alerta()" />
	</div>
	
	<div id="Password">
	
	</div>
	
	</form>
</body>
</html>